package com.cinema.controller;

import com.cinema.service.ChartsService;
import com.cinema.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("charts")
@CrossOrigin
public class ChartsController {
    @Autowired
    ChartsService chartsService;
    @RequestMapping("chartsA")
    public Result chartsA(){
        List<HashMap> list=chartsService.chartA();
        System.out.println(list);
        List categoryList=new ArrayList<>();
        List countList=new ArrayList<>();
        for(HashMap item:list){
            categoryList.add( item.get("category"));
            countList.add( item.get("hallCount"));
        }
        Map map=new HashMap();
        map.put("category",categoryList);
        map.put("hallCount",countList);
        return Result.success(map);
    }
    @RequestMapping("chartsB")
    public Result chartsB(){
        List<HashMap> list=chartsService.chartB();
        System.out.println(list);
        List categoryList=new ArrayList<>();
        List countList=new ArrayList<>();
        for(HashMap item:list){
            categoryList.add( item.get("category"));
            countList.add( item.get("count"));
        }
        Map map=new HashMap();
        map.put("category",categoryList);
        map.put("count",countList);
        return Result.success(map);
    }
    @RequestMapping("chartsC")
    public Result chartsC(){
        List<HashMap> list=chartsService.chartC();
        System.out.println(list);
        List nameList=new ArrayList<>();
        List numList=new ArrayList<>();
        for(HashMap item:list){
            nameList.add( item.get("name"));
            numList.add( item.get("num"));
        }
        Map map=new HashMap();
        map.put("name",nameList);
        map.put("num",numList);
        return Result.success(map);
    }
    @RequestMapping("chartsD")
    public Result chartsD(){
        List<HashMap> list=chartsService.chartD();
        System.out.println(list);
        List genderList=new ArrayList<>();
        List countList=new ArrayList<>();
        for(HashMap item:list){
            genderList.add( item.get("gender"));
            countList.add( item.get("count"));
        }
        Map map=new HashMap();
        map.put("gender",genderList);
        map.put("count",countList);
        return Result.success(map);
    }
    @RequestMapping("chartsE")
    public Result chartsE(){
        List<HashMap> list=chartsService.chartE();
        System.out.println(list);
        List yearList=new ArrayList<>();
        List countList=new ArrayList<>();
        for(HashMap item:list){
            yearList.add( item.get("year"));
            countList.add( item.get("count"));
        }
        Map map=new HashMap();
        map.put("year",yearList);
        map.put("count",countList);
        return Result.success(map);
    }

}